package com.jinxinol.basic.system.web;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.logging.Log;

import com.jinxinol.basic.system.domain.SysConfig;
import com.jinxinol.basic.system.service.ISysConfigService;
import com.jinxinol.core.common.BaseAction;
import com.jinxinol.core.common.ContextHelper;

/**
 * 
 * @company Jinxin Computer Corp.
 * @author wangrong
 * @email qqq36985@163.com
 * @description 数据字典维护
 * @date 2012-9-7
 */
public class ConfigAction extends BaseAction {
	private static final long serialVersionUID = -8004959989512432543L;
	private static final Log logger = ContextHelper.getLogger(ConfigAction.class);
	
	//---------------------------------------------注入Service---------------------------------------------
	@Resource
	private ISysConfigService iSysConfigService;
	
	
	//---------------------------------------------页面对象------------------------------------------------
	private SysConfig sysConfig;
	private List<SysConfig> configList;
	private boolean operResult=false;
	
	
	public String toConfigPage() throws Exception{
		try{
			configList = iSysConfigService.find(sysConfig);
			return "config_page";
		}catch (Exception e) {
			e.printStackTrace();
			logger.error("系统参数加载错误！\n详细日志："+e.getMessage());
			throw new  Exception("系统参数加载错误！\n详细日志："+e.getMessage());
		}
	}
	
	public String toEditPage()throws Exception{
		try{
			if(sysConfig!=null){
				sysConfig = iSysConfigService.findById(sysConfig.getId());
				return "edit_page";
			}
		}catch (Exception e) {
			e.printStackTrace();
			logger.error("跳转参数编辑页面错误！\n详细日志："+e.getMessage());
			throw new  Exception("跳转参数编辑页面错误！\n详细日志："+e.getMessage());
		}
		return "add_page";
	}
	
	public String deleteConfig()throws Exception{
		try{
			 iSysConfigService.delete(sysConfig);
			return toConfigPage();
		}catch (Exception e) {
			e.printStackTrace();
			logger.error("删除参数错误！\n详细日志："+e.getMessage());
			throw new  Exception("删除参数错误！\n详细日志："+e.getMessage());
		}
	} 
	
	public String updateConfig()throws Exception{
		try{
			 iSysConfigService.update(sysConfig);
			 operResult=true;
			return toConfigPage();
		}catch (Exception e) {
			e.printStackTrace();
			logger.error("修改参数错误！\n详细日志："+e.getMessage());
			throw new  Exception("修改参数错误！\n详细日志："+e.getMessage());
		}
	} 
	
	public String addConfig()throws Exception{
		try{
			 iSysConfigService.insert(sysConfig);
			 if(sysConfig.getId()!=null){
				 operResult=true;
			 }
			return toConfigPage();
		}catch (Exception e) {
			e.printStackTrace();
			logger.error("新增参数错误！\n详细日志："+e.getMessage());
			throw new  Exception("新增参数错误！\n详细日志："+e.getMessage());
		}
	} 
	public SysConfig getSysConfig() {
		return sysConfig;
	}

	public void setSysConfig(SysConfig sysConfig) {
		this.sysConfig = sysConfig;
	}

	public List<SysConfig> getConfigList() {
		return configList;
	}

	public void setConfigList(List<SysConfig> configList) {
		this.configList = configList;
	}

	public boolean isOperResult() {
		return operResult;
	}

	public void setOperResult(boolean operResult) {
		this.operResult = operResult;
	}
}
